package top.lilele.adminSystem.service;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import top.lilele.adminSystem.entity.AdminSpaceEntity;
import top.lilele.adminSystem.mapper.AdminSpaceMapper;
import top.lilele.adminSystem.numEnum.SpaceTypeEnum;
import top.lilele.adminSystem.vo.SpaceListVo;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lilele
 */
@Service
public class AdminSpaceService {

    @Resource
    AdminSpaceMapper adminSpaceMapper;

    public String add(AdminSpaceEntity adminSpaceEntity) {
        adminSpaceMapper.insert(adminSpaceEntity);
        return adminSpaceEntity.getId();
    }

    public List querySpaceList() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("asp.createdId", StpUtil.getLoginIdAsString());
        List<SpaceListVo> list = adminSpaceMapper.queryMySpaceList(queryWrapper);
        list.stream().forEach(item -> {
            item.setTypeLabel(SpaceTypeEnum.getMessageByKeyId(item.getType()));
        });
        return list;
    }

    public AdminSpaceEntity querySpaceById(String id) {
        AdminSpaceEntity adminSpaceEntity = adminSpaceMapper.selectById(id);
        return adminSpaceEntity;
    }

    public void updateSpaceById(AdminSpaceEntity adminSpaceEntity) {
        adminSpaceMapper.updateById(adminSpaceEntity);
    }
}
